package com.pms.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.pms.entity.Project;
import com.pms.util.DBHelp;
import com.pms.util.RowMapper;

public class ProjectDao {
	private DBHelp<Project> db=new DBHelp<Project>();
	public List<Project> getProjectByUserId(String userId){
		String sql="SELECT * FROM t_project WHERE projectid IN(SELECT projectid FROM t_user_project WHERE userid= ? ) order by createtime desc";
		return db.executeQueryForList(sql, new ProjectRowMapper(),userId);
	}
	public void save(Project project){
		String sql="INSERT into t_project(projectid,projectname,`desc`,createtime) VALUES(?,?,?,?)";
		db.executeSQL(sql,project.getProjectId(),project.getProjectName(),project.getDesc(),project.getCreateTime());
	}
	public class ProjectRowMapper implements RowMapper<Project>{

		public Project mapRow(ResultSet rs) throws SQLException {
			Project project=new Project();
			project.setProjectId(rs.getString("projectId"));
			project.setProjectName(rs.getString("projectName"));
			project.setDesc(rs.getString("desc"));
			project.setCreateTime(rs.getString("createTime"));
			return project;
		}
		
		
	}
}
